﻿using IOP.SgrA.GLSL;
using IOP.SgrA.SilkNet.Vulkan;
using IOP.SgrA.SilkNet.Vulkan.Scripted;
using Silk.NET.Vulkan;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VkSample114
{
    [ShaderVersion("460")]
    [GLSLExtension("GL_ARB_separate_shader_objects : enable")]
    [GLSLExtension("GL_ARB_shading_language_420pack : enable")]
    [VertexInputBinding(0, 12)]
    [VertexInputBinding(1, 12)]
    [VertexInputBinding(2, 24)]
    public partial class CommonVert : GLSLVert
    {
        [PushConstant(64, 0)]
        public ConstantVals myConstantVals { get; set; }
        [UniformBuffer(0, 0, DescriptorSetTarget.RenderObject)]
        public BufferVals myBufferVals { get; set; }

        [VertInput(0, Format.R32G32B32Sfloat, Offset = 0, Binding = 0)]
        public vec3 aPosition {  get; set; }
        [VertInput(1, Format.R32G32B32Sfloat, Offset = 0, Binding = 1)]
        public vec3 bPosition {  get; set; }
        [VertInput(2, Format.R32G32B32Sfloat, Offset = 0, Binding = 2)]
        public vec3 cPosition {  get; set; }
        [VertInput(3, Format.R32G32B32Sfloat, Offset = 12, Binding = 2)]
        public vec3 inTexCoor {  get; set; }
        [ShaderOutput(0)]
        public vec2 outTexCoor { get; set; }

        public override void main()
        {
            vec3 tPosition; //融合后的结果顶点坐标
            if (myBufferVals.uBfb <= 1.0f)
            { //若融合比例小于等于1，则需要执行的是1、2 号关键帧的融合
                tPosition = mix(aPosition, bPosition, myBufferVals.uBfb);
            }
            else
            { //若融合比例大于1，则需要执行的是2、3 号关键帧的融合
                tPosition = mix(bPosition, cPosition, myBufferVals.uBfb - 1.0f);
            }
            outTexCoor = new vec2(inTexCoor.x, 1.0f - inTexCoor.y); //输出到片元着色器的纹理坐标
            gl_Position = myConstantVals.mvp * new vec4(tPosition, 1.0f); //计算最终的顶点位置
        }
    }
}
